package com.yh.csx.event.test;

import com.yh.csx.bsf.cat.method.CatMethod;
import com.yh.csx.bsf.core.util.JsonUtils;
import com.yh.csx.event.client.event.EventSubscribe;
import com.yh.csx.event.domain.order.Order;
import com.yh.csx.event.store.gateway.log.LogRepository;
import com.yh.csx.event.store.gateway.log.dataobject.OperateLogDo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author zhangsheng
 * @date 2021/9/6 15:42
 */
@Slf4j
@Service
public class ScmService {

    @Autowired
    private LogRepository logRepository;

    @CatMethod("event")
    @EventSubscribe(topic = "csx_b2b_event_oms_topic", consumerGroup = "event_sub_scm_order")
    public void receive(Order order) {
        log.info("=receive=>order:{}", order);
        OperateLogDo log = new OperateLogDo();
        log.setLogType("scm-oms-order");
        log.setContext(JsonUtils.serialize(order));
        log.setRefId(order.getOrderId());
        log.setCreateTime(new Date());
        log.setCreator("sys");
        log.setRemark("sys");
        logRepository.save(log);
    }

}
